﻿package Interface.BattleStartClasses
{	
	import Core.PlayerInfo;
	
	import Interface.AvatarLoader;

	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.events.Event;	

	public class PlayerInfoBlock extends Sprite
	{
		private var FAvatar:AvatarLoader;
		private var FNameText:TextField;
		private var FRatingText:TextField;
		
		public function PlayerInfoBlock():void
		{			
			FAvatar = getChildByName('BlockPhoto') as AvatarLoader;
			FNameText = getChildByName('NameText') as TextField;
			FRatingText = getChildByName('RatingText') as TextField;
			
			FAvatar.addEventListener(Event.COMPLETE, OnAvatarLoaded);
		}
		
		public function set User(AUser:PlayerInfo):void
		{
			FNameText.text = AUser.Name;
			FRatingText.text = AUser.Rating;
			FAvatar.Photo = AUser.Photo;			
		}
		
		private function OnAvatarLoaded(e:Event):void
		{
			dispatchEvent(new Event(Event.COMPLETE));
		}
	}	
}
